package org.sy.lab.多线程基础._2_同步._1_synchronized._1_锁的对象;

import java.util.concurrent.TimeUnit;

public class Main {

	public static void main(String[] args) {
		
		//UnsafeTick tick = new UnsafeTick();
		
		//锁住该对象
		//public synchronized void method { } 方法锁
		//synchronized(this) { } 代码锁
		//Tick1 tick = new Tick1();
		
		//锁住该类
		//public synchronized static void method { } 方法锁
		//synchronized(Test.class) { } 代码锁
		//Tick2 tick = new Tick2();
		
		//锁住非依赖属性
		//synchronized(o) {} 代码锁
		Tick3 tick = new Tick3();
		
		MyThread myThread = new MyThread(tick);
		
		for (int i = 0; i < 10; i++) {
			Thread thread = new Thread(myThread);
			thread.start();
		}
		
		try {
			TimeUnit.SECONDS.sleep(1);
		} catch (InterruptedException e) {
			e.printStackTrace();
		}
		System.out.println(tick.getNum());
	}
}
